﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelDinhMuc.Model;
namespace TinhNguyenVatLieuSanBay
{
    public partial class FrmTimkiemDungCu : Form
    {
        public DungCu dungcu;
        DINHMUCSANBAYDB db = new DINHMUCSANBAYDB();
        IList<DungCu> lstdungcu;
        public FrmTimkiemDungCu(string madungcu)
        {
            InitializeComponent();
            InitDungCu(madungcu.ToUpper().Trim());
        }

        private void InitDungCu(string timkiem)
        {
            IList<DungCu> lsttmp;
            lstdungcu = db.SelectAllDungCu().ExecuteTypedList<DungCu>();
            lsttmp = lstdungcu.Where(x => x.TenDungCu.Contains(timkiem)).ToList();
            dungCuBindingSource.DataSource = lsttmp;
        }

        private void gvdungcu_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            dungcu = gvdungcu.CurrentRow.DataBoundItem as DungCu;
            this.Close();
        }

        private void FrmTimkiemDungCu_FormClosed(object sender, FormClosedEventArgs e)
        {
            dungcu = gvdungcu.CurrentRow.DataBoundItem as DungCu;
        }

        private void txttimkiem_TextChanged(object sender, EventArgs e)
        {
            IList<DungCu> lsttmp;
            lstdungcu = db.SelectAllDungCu().ExecuteTypedList<DungCu>();
            lsttmp = lstdungcu.Where(x => x.MaDungCu.Contains(txttimkiem.Text.ToUpper().Trim())).ToList();
            dungCuBindingSource.DataSource = lsttmp;
        }
    }
}
